home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
mac
/
files
/
infodata
/
callbook.tar
/
callbook_1.3
/
endian.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-17
|
2KB
|
85 lines
/*
* Telnet callsign server sources copyright 1989 by Devon Bowen, KA2NRC.
* You may distribute and modify these files as you please as long as
* as long as credit to the original creator is given. Please report any
* bug fixes or modification to bowen@cs.buffalo.edu.
*/
#include <stdio.h>
#include <sys/file.h>
main(argc, argv)
int argc;
char **argv;
{
int field, fi, fo, cc;
char fsearch[BUFSIZ], fdata[BUFSIZ];
unsigned short byte2;
unsigned int byte4;
field = atoi(argv[1]);
sprintf(fsearch, "callsign.%d.search", field);
sprintf(fdata, "callsign.%d.data", field);
fi = open(fsearch, O_RDONLY);
fo = open(strcat(fsearch,"_flip"), O_WRONLY | O_CREAT, 0644);
while (cc = read(fi, &byte2, sizeof(byte2))) {
if (cc == -1) {
fprintf(stderr, "READ ERROR!\n");
exit(1);
}
byte2 = ((byte2 & 0xff00) >> 8) | ((byte2 & 0xff) << 8);
if (write(fo, &byte2, sizeof(byte2)) == -1) {
fprintf(stderr, "WRITE ERROR!\n");
exit(1);
}
if ((cc = read(fi , &byte4, sizeof(byte4))) == -1) {
fprintf(stderr, "READ ERROR!\n");
exit(1);
}
byte4 = ((byte4 & 0xff000000) >> 24) |
((byte4 & 0x00ff0000) >> 8) |
((byte4 & 0x0000ff00) << 8) |
((byte4 & 0x000000ff) << 24);
if (write(fo, &byte4, sizeof(byte4)) == -1) {
fprintf(stderr, "WRITE ERROR!\n");
exit(1);
}
}
close(fi);
close(fo);
fi = open(fdata, O_RDONLY);
fo = open(strcat(fdata,"_flip"), O_WRONLY | O_CREAT, 0644);
while (cc = read(fi, &byte4, sizeof(byte4))) {
if (cc == -1) {
fprintf(stderr, "READ ERROR!\n");
exit(1);
}
byte4 = ((byte4 & 0xff000000) >> 24) |
((byte4 & 0x00ff0000) >> 8) |
((byte4 & 0x0000ff00) << 8) |
((byte4 & 0x000000ff) << 24);
if (write(fo, &byte4, sizeof(byte4)) == -1) {
fprintf(stderr, "WRITE ERROR!\n");
exit(1);
}
}
close(fi);
close(fo);
}